package com.liuyu.common.framework.insurance.picc.gd.vo.request;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.liuyu.common.framework.common.util.IdUtils;
import com.liuyu.common.framework.insurance.picc.gd.vo.PiccGdRequestHead;
import com.liuyu.common.framework.insurance.picc.gd.vo.request.surrend.PiccGdSurrendRequest;
import com.liuyu.common.framework.insurance.picc.gd.vo.request.surrend.PiccGdSurrendRequestBody;
import com.thoughtworks.xstream.XStream;

/**
 * @author LiuYu
 * @Project:easyorder
 * @Title:${TITLE}
 * @Description:${todo}
 * @date 2017/9/8 000816:42
 * @Copyright:liuyu
 * @version:V1.0
 */
public class SurrendExample {
    private static XStream xStream;
    public static final String app_secret = "a87c563fbff711e95912da4ca9f0c804";

    static {
        xStream = new XStream();
        xStream.autodetectAnnotations(true);
    }

    public static void main(String[] args) throws Exception {
        //投保请求类
        PiccGdSurrendRequest request = new PiccGdSurrendRequest();

        PiccGdRequestHead head = new PiccGdRequestHead();
        head.setAppKey("EOP44197100");
        head.setOrderNo(IdUtils.snowflakeNextIdStr());

        Digester md5 = new Digester(DigestAlgorithm.MD5);
        String digestHex = md5.digestHex(head.getOrderNo() + app_secret);
        head.setSign(digestHex);

        request.setRequestHead(head);
        PiccGdSurrendRequestBody queryRequest = new PiccGdSurrendRequestBody();
        queryRequest.setPolicyNo("PLDO202144190000000131");
        request.setRequestBody(queryRequest);
        String xml = xStream.toXML(request);
        System.out.println(xml);
        HttpResponse response = HttpRequest.post("http://183.236.83.138:8777/EasyOrder/webservice/surrend").body(xml).execute();
        System.out.println(response.body());

    }


}

